<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>EASY后台-上传</title>
    <link rel="icon" th:href="@{/static/images/favicon.ico}">
    <link rel="stylesheet" th:href="@{/static/css/common.css}">
    <link rel="stylesheet" th:href="@{/static/layui/css/layui.css}">
</head>
<body>
<div class="easy-container">
    <form class="layui-form" id="dataForm" lay-filter="dataForm">
        <div class="layui-form-item">
            <label class="layui-form-label required">文件</label>
            <div class="layui-input-block">
                <button type="button" class="layui-btn layui-btn-normal" id="uploadBtn">选择文件</button>
            </div>
        </div>
    </form>
</div>
</body>

<script th:src="@{/static/js/jquery.js}"></script>
<script th:src="@{/static/layui/layui.js}"></script>
<script type="text/javascript" th:inline="javascript">
    layui.use(['element', 'layer', 'table', 'laydate', 'form', 'upload'], function () {
        var element = layui.element;
        var layer = layui.layer;
        var table = layui.table;
        var laydate = layui.laydate;
        var form = layui.form;
        var upload = layui.upload;

        // 保存
        upload.render({
            elem: '#uploadBtn',
            url: '/sysFile/upload',
            accept: 'file',
            multiple: false,
            done: function(response){
                if (response.code === 200) {
                    // 关闭
                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                    // 刷新
                    parent.location.reload();

                    layer.msg('上传成功', {icon: 1});
                } else {
                    layer.msg(response.msg, {icon: 0});
                }
            },
            error: function (index, upload, res, xhr) {
                layer.msg('上传失败', {icon: 0});
            }
        });

    });
</script>
</html>